---

- name: Prepare dnf source with Consul packages
  ansible.builtin.shell:
    cmd: |
          dnf install -y dnf-plugins-core
          dnf config-manager --add-repo https://rpm.releases.hashicorp.com/fedora/hashicorp.repo
    chdir: /root/
    
- name: Install consul-template
  ansible.builtin.dnf:
    name: consul-template
    state: latest

- name: init config directory for consul-template
  ansible.builtin.file:
    path: /etc/consul-template.d/
    state: directory

- name: init template directory
  ansible.builtin.file:
    path: "{{ default_consul_template_location }}"
    state: directory

- name: generate consul-template configuration for local consul client
  ansible.builtin.template:
    src: consul-template-config.hcl.j2
    dest: /etc/consul-template.d/consul-template-config.hcl

- name: copy consul-template service
  ansible.builtin.copy:
    src: consul-template.service
    dest: /etc/systemd/system/consul-template.service

- name: Enable and restart consul-template service
  ansible.builtin.service:
    name: consul-template
    daemon_reload: true
    enabled: yes
    state: restarted
